<?php

use Illuminate\Database\Seeder;

class FakeUserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //
        $faker = Faker\Factory::create('zh_CN');

        $output = new \Symfony\Component\Console\Output\ConsoleOutput();
        $progress = new \Symfony\Component\Console\Helper\ProgressBar($output, 1000);
        $progress->setFormat(" 内存消耗:%memory% %elapsed:6s%/%estimated:-6s%\n [%bar%] %percent:3s%%");
        $progress->start();

        for ($i = 0; $i < 1000; $i++) {
            $datas = [];
            foreach (range(1, 200) as $_) {
                $datas[] = [
                    'phone' => $faker->phoneNumber,
                    'address_info' => json_encode([
                        'phone' => $faker->phoneNumber,
                        'name' => $faker->name,
                        'address' => $faker->address,
                    ], JSON_UNESCAPED_UNICODE),
                    'created_at' => \Carbon\Carbon::now(),
                    'updated_at' => \Carbon\Carbon::now(),
                ];
            }

            $progress->advance();
            DB::table('fake_user')->insert($datas);
        }

        $progress->finish();
        echo "\n";
    }
}
